package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressSum;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressSumMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressSumParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressSumResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressSumService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 合计分配管理 服务实现类
 */
@Service
public class ToolExpressSumServiceImpl extends ServiceImpl<ToolExpressSumMapper, ToolExpressSum> implements ToolExpressSumService {

    @Override
    public void add(ToolExpressSumParam param){
        ToolExpressSum entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressSumParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressSumParam param){
        ToolExpressSum oldEntity = getOldEntity(param);
        ToolExpressSum newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressSumResult findBySpec(ToolExpressSumParam param){
        return null;
    }

    @Override
    public List<ToolExpressSumResult> findListBySpec(ToolExpressSumParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressSumParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findlistHebingPageBySpec(ToolExpressSumParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findlistHebingPageBySpec(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressSumParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressSum getOldEntity(ToolExpressSumParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressSum getEntity(ToolExpressSumParam param) {
        ToolExpressSum entity = new ToolExpressSum();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public void deleteBySpec(ToolExpressSumParam expressSumParam) {
		this.baseMapper.deleteBySpec(expressSumParam);
	}

	@Override
	public boolean saveBatchList(List<ToolExpressSumParam> listadd) {
		return this.baseMapper.saveBatchList(listadd);
	}

}
